package com.littcore.saap.assistant.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import com.littcore.dao.page.IPageList;
import com.littcore.dao.ql.PageParam;
import com.littcore.saap.assistant.dao.UserFavouriteDao;
import com.littcore.saap.assistant.po.UserFavourite;
import com.littcore.saap.assistant.service.IUserFavouriteService;
import com.littcore.saap.assistant.webservice.IUserFavouriteWebService;


public class UserFavouriteServiceImpl implements IUserFavouriteService,IUserFavouriteWebService {
	@Resource
	private UserFavouriteDao favouriteDao;
	
	public UserFavourite findUnique(String moduleCode,int recordId,int createBy,int tenantId)
	{	
	  return favouriteDao.findUnique(moduleCode, recordId, createBy, tenantId);
	}
	
	/**
	 * 根据业务记录查找所有关注人.
	 *
	 * @param moduleCode the module code
	 * @param recordId the record id
	 * @param tenantId the tenant id
	 * @return the list
	 */
	public List<UserFavourite> findByRecord(String moduleCode,int recordId, int tenantId)
  { 
	  String hql = "from UserFavourite where moduleCode=? and recordId=? and tenantId=?";
    return favouriteDao.listAll(hql, new Object[]{moduleCode, recordId, tenantId});
  }
	
	public IPageList listPage(PageParam pageParam) {
		String listHql = "select obj from UserFavourite obj" +
				"-- and obj.tenantId={tenantId}" + 
				"-- and obj.moduleCode={moduleCode}" + 
			  "-- and obj.recordId={recordId}" +
				"-- and obj.createBy={createBy}";
		if(!StringUtils.isEmpty(pageParam.getCond("recordIds"))){
			listHql+="or obj.recordId in ("+pageParam.getCond("recordIds")+")";
		}
        
		return favouriteDao.listPage(listHql, pageParam);
	}


}
